<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vueCms.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title><% title %></title>
    <meta name="description" content="使用vue3+nestjs搭建的后台管理系统-沉默小管">
    <meta name="author" content="沉默小管-VueCms">
    <meta name="keywords" content="vueCms,vueAdmin,vue,cms,admin,vueCms_xg,沉默小管">
    <% for (var i in cssCdn) { %>
    <link href="<%= cssCdn[i] %>" type="text/css" rel="stylesheet" />
    <% } %>
    <script>
        //需要替换的域名
        const domains = [
            "cdn.bootcdn.net/ajax/libs",
            "www.staticfile.org",
            "cdn.baomitu.com",
            "cdn.bytedance.com",
            "www.jsdelivr.com",
            "unpkg.com",
        ]
        //重试次数
        const maxRetry = 3;
        const retryInfo = {}
        window.addEventListener('error',(e)=>{
            //通过标签，判断是脚本爆出的错误
            const tag = e.target
            //什么时候触发脚本加载失败？
            if(tag.tagName === "SCRIPT" && !(e instanceof ErrorEvent)){
                let url = new URL(tag.src)
                if(!retryInfo[url.pathname]){
                    retryInfo[url.pathname]={
                        time:0,
                        nextIndex:0,
                    }
                }
                const info = retryInfo[url.pathname]
                if(maxRetry>=info.time){
                    url.host = domains[info.nextIndex]
                    //阻塞页面后续的加载
                    document.write(`<script src="${url.toString()}">\<\/script>`)
                    info.time++;
                    info.nextIndex = (info.nextIndex+1)%domains.length
                }
            }
        },true)
    </script>
</head>
<body>
<div id="app"></div>
<% for (let i in jsCdn) { %>
<script src="<%= jsCdn[i] %>"></script>
<% } %>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
